package com.shijiu.controller;

import cn.hutool.core.util.StrUtil;
import com.shijiu.annotation.RepeatSubmit;
import com.shijiu.common.Result;
import com.shijiu.pojo.Goods;
import com.shijiu.pojo.ShopOrder;
import com.shijiu.service.ShopOrderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.Map;

/**
 * @Author xlj
 * @Date Created in  2023/4/24 16:41
 * @DESCRIPTION:
 * @Version V1.0
 */
@RestController
@RequestMapping("shopOrder")
@Transactional(rollbackFor = Exception.class)
public class ShopOrderController {
    @Resource
    private ShopOrderService shopOrderService;

    @ApiOperation("创建订单")
    @PostMapping("createOrder")
    public Result createOrder(@RequestBody Map<String, Object> requestBodyMaps) throws ParseException {
        return shopOrderService.createOrder(requestBodyMaps);
    }

    @ApiOperation("分页查询订单")
    @PostMapping("selectOrderByPage")
    public Result selectOrderByPage(@RequestBody Map<String, Object> requestBodyMaps) throws ParseException {
        return shopOrderService.selectOrderListByPage(requestBodyMaps);
    }
    @ApiOperation("删除订单")
    @RepeatSubmit(interval = 2000, message = "接口请求过于频繁")
    @PostMapping("deletedById")
    public Result deletedById(@RequestBody ShopOrder shopOrder){
        //admin  的id 未为 1
        String shopOrderId = shopOrder.getId();
        if (StrUtil.isBlank(shopOrderId)) {
            return Result.fail(Integer.parseInt("505"),"id不能为空");
        }
        return shopOrderService.deletedById(shopOrderId);
    }
}
